package com.hospital.servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hospital.util.DbUtil;
@WebServlet("/manage/MedicineContorlServlet")
public class MedicineContorlServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {//通过方法的名称不同进行不同药品基础信息的添加
		// TODO Auto-generated method stub
		String method = request.getParameter("method");
		if ("add".equals(method)) {
			String drugstroge = request.getParameter("drugstroge").trim();
			String sql = "insert into t_drugstorage_name(flmc , addtime) values('"
					+ drugstroge +"', '" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()) + "')";
			DbUtil.add_modify(sql);
			request.getRequestDispatcher("/manage/drugstorage_info_manage.jsp").forward(request, response);
		} else if ("del".equals(method)) {
			String[] id = request.getParameterValues("selectFlag");
			DbUtil.del("t_drugstorage_name", id);
			request.getRequestDispatcher("/manage/drugstorage_info_manage.jsp").forward(request, response);
		} else if ("modify".equals(method)) {
			int id = Integer.parseInt(request.getParameter("id"));
			String drugstroge = request.getParameter("drugstroge").trim();
			String sql = "update t_drugstorage_name set flmc = '" + drugstroge + "' where id = " + id;
			DbUtil.add_modify(sql);
			request.getRequestDispatcher("/manage/drugstorage_info_manage.jsp").forward(request, response);
		} 
		//////////////////////////////////////////////////////////////////////////////////////////////
		else if ("addModel".equals(method)) {
			String ypjx = request.getParameter("ypjx").trim();
			String sql = "insert into t_ypmodel_set(ypjx , addtime) values('" + ypjx +"', '" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()) + "')";
			DbUtil.add_modify(sql);
			request.getRequestDispatcher("/manage/ypmodel_info_manage.jsp").forward(request, response);
		} else if ("modifyModel".equals(method)) {
			int id = Integer.parseInt(request.getParameter("id"));
			String ypjx = request.getParameter("ypjx").trim();
			String sql = "update t_ypmodel_set set ypjx = '" + ypjx + "' where id = " + id;
			DbUtil.add_modify(sql);
			request.getRequestDispatcher("/manage/ypmodel_info_manage.jsp").forward(request, response);
		} else if ("delModel".equals(method)) {
			String[] id = request.getParameterValues("selectFlag");
			DbUtil.del("t_ypmodel_set", id);
			request.getRequestDispatcher("/manage/ypmodel_info_manage.jsp").forward(request, response);
		}
		//////////////////////////////////////////////////////////////////////////////////////////////
		else if ("adddw".equals(method)) {
			String dwmc = request.getParameter("dwmc").trim();
			String sql = "insert into t_meterage_set(dwmc , addtime) values('" + dwmc +"', '" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()) + "')";
			DbUtil.add_modify(sql);
			request.getRequestDispatcher("/manage/ypdw_info_manage.jsp").forward(request, response);
		} else if ("modifydw".equals(method)) {
			int id = Integer.parseInt(request.getParameter("id"));
			String dwmc = request.getParameter("dwmc").trim();
			String sql = "update t_meterage_set set dwmc = '" + dwmc + "' where id = " + id;
			DbUtil.add_modify(sql);
			request.getRequestDispatcher("/manage/ypdw_info_manage.jsp").forward(request, response);
		} else if ("deldw".equals(method)) {
			String[] id = request.getParameterValues("selectFlag");
			DbUtil.del("t_meterage_set", id);
			request.getRequestDispatcher("/manage/ypdw_info_manage.jsp").forward(request, response);
		}
		
	}
}
